import 'dart:async';
import 'package:event_bus/event_bus.dart';

typedef void EventCallback<T>(T event);

class EventBusUtils {
  static final EventBus _eventBus = EventBus();

  // 开启eventbus订阅并回调
  static StreamSubscription on<T>(EventCallback<T> callback) {
    StreamSubscription stream = _eventBus.on<T>().listen((event) {
      callback(event);
    });
    return stream;
  }

  // 发送消息
  static fire(event) {
    _eventBus.fire(event);
  }

  // 移除steam
  static cancel(StreamSubscription steam) {
    steam.cancel();
  }
}
